|
|
|
|
|
|
|
Listing 21.44. Coding the SetUser method. |
|
|
|
|
|
|
|
|
Public Sub SetUser()
'
' set up user details
'
Dim ctlTemp As Control
'
' create object & set properties
Set objUser = New usrObject
objUser.DBName = Data1.DatabaseName
objUser.LoginTitle = "Security Test Form"
'
' login and set up rights
If objUser.UserLogin = True Then
objLog.WriteLog "LogIn", objUser.UserID
For Each ctlTemp In Controls
If TypeOf ctlTemp Is CommandButton Then
ctlTemp.Enabled = objUser.CheckRights(ctlTemp.Caption,
ctlTemp.Index)
End If
Next
Else
End ' reject user
End If
'
End Sub |
|
|
|
|
|
|
|
|
Notice that the control array index was used to actually indicate the rights level for each button. The Close button is index 0 (no rights needed), but the Delete button is index 4 (Read/Mod/Add/Del rights). This is a very efficient way to gather rights data for a user. Note also that the audit log is written if the user is successful in logging into the form. |
|
|
|
|
|
|
|
|
Now you can add the code for the button array. This allows users (if they have the proper rights) to add, edit, or delete records from the table. Add the code from Listing 21.45 to the cdmBtn_Click event. |
|
|
|
|
|
|
|
|
Listing 21.45. Adding code to the cmdBtn_Click event. |
|
|
|
|
|
|
|
|
Private Sub cmdBtn_Click(Index As Integer)
'
' handle button clicks
'
On Error GoTo LocalErr
'
Select Case Index
Case 0 ' close
objLog.WriteLog "LogOut", objUser.UserID
objUser.LogUser urLogOut |
|
|
|
|
|